﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;

using JXMSTC.SmartBusiness.BFL.BLLFactory;
using JXMSTC.SmartBusiness.BFL.IBLL;

public partial class Common_Controls_login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!this.IsPostBack)
        //{
        //    //判断顾客是否登录，若customerID为0，则未登录，即匿名，反之，则为登录
        //    string customerID = (string)Session["CustomerID"];

        //    if (customerID == "0")
        //    {
        //        //显示登录框
        //        pnlLogin.Visible = true;
        //        //隐藏会员中心
        //        pnlExit.Visible = false;
        //    }
        //    else
        //    {
        //        //顾客已经登录后，则隐藏登录框
        //        pnlLogin.Visible = false;
        //        //显示会员中心和退出按钮
        //        pnlExit.Visible = true;
        //    }
        //}
    }

    /// <summary>
    /// 对数据进行加密
    /// </summary>
    /// <param name="strPassword"></param>
    /// <returns></returns>
    protected byte[] GetPassword(string strPassword)
    {
        //转化为二进制数组
        UnicodeEncoding UE = new UnicodeEncoding();
        byte[] arSource = UE.GetBytes(strPassword);
        //哈希加密
        SHA1 SHharsh = new SHA1Managed();
        byte[] arHarshValue = SHharsh.ComputeHash(arSource);
        //返回一个二进制数组
        return arHarshValue;
    }
    
    /// <summary>
    /// 点击登录按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
    {
        //if((txtUserName.Text.Trim()!="")&&(txtPassword.Text.Trim()!=""))
        //{
        //    //对密码进行加密
        //    byte[] password=this.GetPassword(txtPassword.Text);

        //    //从工厂中获取顾客对象
        //    ICustomer customer = BLLAccess.CreateCustomer();   
        //    //判断登陆是否成功
        //    if (customer.Login(txtUserName, password))
        //    {
        //        //登录成功
        //        pnlLogin.Visible = false;
        //        pnlExit.Visible = true;
        //        this.lblMessage.Text="";

        //        //把顾客登录名保存在Session中
        //        Session["CustomerID"] = txtUserName.Text;
        //    }
        //    else
        //    {
        //        //登录失败
        //        pnlLogin.Visible = true;
        //        pnlExit.Visible = false;
        //        this.lblMessage.Text = "用户名或密码错误";

        //    }
        //}
    }

    /// <summary>
    /// 顾客登录后，点击退出按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExit_Click(object sender, EventArgs e)
    {
        ////登录框显示，会员中心隐藏
        //pnlLogin.Visible = true;
        //pnlExit.Visible = false;
        //Session["CustomerID"] = "0";

    }

    /// <summary>
    /// 点击注册按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnRegesiter_Click(object sender, ImageClickEventArgs e)
    {
        //链接到注册按钮
        //Response.Redirect("UserReg.aspx");
    }
    
}
